from django.db import models
from utils.BaseModel import BaseModel
# Create your models here.


class Category(BaseModel):
    cname = models.CharField(max_length=50, verbose_name='分类名称')
    parent = models.ForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, verbose_name='上级分类',related_name="children")
    ishome = models.BooleanField(default=True, verbose_name='是否推荐在首页')
    isgood = models.BooleanField(default=True, verbose_name='是否为精品课分类')
    class Meta:
        verbose_name = '课程分类'
        db_table="fgcategory"
    def __str__(self):
        return self.cname


class Teacher(BaseModel):
    name=models.CharField(max_length=50,verbose_name='教师名称')
    img=models.CharField(max_length=150,verbose_name='教师头像')
    work=models.CharField(max_length=50,verbose_name='职位')
    desc=models.TextField(verbose_name='个人简介')
    class Meta:
        verbose_name='教师'
        db_table='fgteacher'
    def __str__(self):
        return self.name


class Course(BaseModel):
    coursename=models.CharField(max_length=50,verbose_name='课程名称')
    coursedesc=models.CharField(max_length=150,verbose_name='课程描述')
    content=models.TextField(verbose_name='课程内容简介')
    price=models.DecimalField(verbose_name="课程价格",max_digits=7,decimal_places=2)
    cate=models.ForeignKey(Category,on_delete=models.CASCADE,verbose_name='课程分类')
    level=models.IntegerField(choices=((0,"零基础"),(1,"初级"),(2,"高级")),default=0,verbose_name='难度')
    ishot=models.BooleanField(default=True,verbose_name="是否为热门")
    ishome=models.BooleanField(default=True,verbose_name="是否推荐到首页")
    cover=models.CharField(max_length=200,verbose_name='课程页面图片')
    timeline=models.IntegerField(default=0,verbose_name='时长')
    students=models.IntegerField(default=0,verbose_name='学习人数')
    video=models.CharField(max_length=200,verbose_name='宣传视频')
    teacher=models.ForeignKey(Teacher,on_delete=models.CASCADE,verbose_name='当前课程的老师')
    class Meta:
        db_table="fgcourse"

    def __str__(self):
        return self.coursename


